#include "Precompile.h"
#include "ISoundSystem.h"

namespace Sound{
	void ISoundSystem::playSound(std::string name, bool loop){
		std::map<std::string,ISoundPtr>::iterator itr = m_playingSounds.find(name);
		if(itr != m_playingSounds.end()){
			itr->second->play(loop);
			return;
		}

		itr = m_soundDB.find(name);
		if(itr != m_soundDB.end()){
			m_playingSounds[name] = itr->second;
			itr->second->play(loop);
			return;
		}

		LOG_DEBUG("Sound not found!");
		assert(0);
	}

	void ISoundSystem::stopPlayingSound(std::string name){
		std::map<std::string,ISoundPtr>::iterator itr = m_playingSounds.find(name);
		if(itr != m_playingSounds.end()){
			itr->second->stop();
			m_playingSounds.erase(itr);
		}
		else{
			LOG_DEBUG("No such sound playing!");
		}	
	}
}